<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
	<title>Processing.js test of nf() (1)</title>
	<script type="text/javascript" src="../../../processing.js"></script>
	<style type="text/css">
	html, body
	{
		background: #EEE;
		font-family: Arial;
		font-size: 13px;
		margin: 0;
		padding: 0;
	}
	h1
	{
		background: #385C85;
		color: #FFF;
		padding: 10px;
		padding-left: 20px;
		margin-top: 0px;
	}
	h1 a
	{
		color: #FFF;
	}
	h2
	{
		padding-left: 20px;
	}
	p
	{
		padding-left: 20px;
		line-height: 1.3em;
	}
	p a
	{
		color: #385C85;
	}
	canvas
	{
		margin: 10px 0;
	}
	pre
	{
		margin-left: 20px;
		margin-right: 20px;
		padding: 5px;
		background: #FFF;
		border-top: 1px solid #333;
		border-bottom: 1px solid #333;
	}
	div.ref-col
	{
		float: left;
		width: 32%;
	}
	</style>
</head>
<body>

	<h1>nf() test (1)</h1>
	<h2>Test 1</h2>
	<p>See tests 6 to 8 for the values you'd think would be returned. Processing has the same behaviour.</p>
	<h2>Tests 6 to 8</h2>
	<p>The values you'd think test 1 would return, but doesn't.</p>
	<p>

	<!-- copy paste your processing code below this script tag -->
	<script id="script" type="application/processing">
boolean errors=false;

int xcoord=5;
int xoff=10;
int ycoord=35;
int yinc=15;

void setup() {
	size(500,400);
	background(50);
	noLoop();
} 

void draw() {
        String[] res1=new String[3];
        res1[0]="-01";
        res1[1]="20";
        res1[2]="300";
        int[] inp1=new int[3];
        inp1[0]=-1;
        inp1[1]=20;
        inp1[2]=300;
        outputArr(1,"nf({-1,20,300}, 3)",nf(inp1, 2),res1);

        String[] res2=new String[3];
        res2[0]="-001.00";
        res2[1]="020.02";
        res2[2]="300.01";
        float[] inp2=new float[3];
        inp2[0]=-1.002;
        inp2[1]=20.02;
        inp2[2]=300.0123;
        outputArr(2,"nf({-1.002,20.02,300.0123}, 3, 2)",nf(inp2, 3, 2),res2);
        
        String[] res3=new String[3];
        res3[0]="-1";
        res3[1]="20";
        res3[2]="300";
        int[] inp3=new int[3];
        inp3[0]=-1;
        inp3[1]=20;
        inp3[2]=300;
        outputArr(3,"nf({-1,20,300}, -1)",nf(inp3, -1),res3);
        
        String[] res4=new String[3];
        res4[0]="-001";
        res4[1]="000";
        res4[2]="000";
        float[] inp4=new float[3];
        inp4[0]=-1.002;
        inp4[1]=0.49;
        inp4[2]=0.5;
        outputArr(4,"nf({-1.002,0.49,0.5}, 3, -1)",nf(inp4, 3, -1),res4);
        
        String[] res5=new String[3];
        res5[0]="-001";
        res5[1]="001";
        res5[2]="002";
        float[] inp5=new float[3];
        inp5[0]=-1.002;
        inp5[1]=1.49;
        inp5[2]=1.5;
        outputArr(5,"nf({-1.002,1.49,1.5}, 3, -1)",nf(inp5, 3, -1),res5);

	xcoord=300;
	ycoord=35;

        output(6,"nf(-1, 3)",nf(-1, 3),"-001");
        output(7,"nf(20, 3)",nf(20, 3),"020");
        output(8,"nf(300, 3)",nf(300, 3),"300");

	String errMsg="";
	if (errors) {
		fill(255,0,0);
		errMsg="RED tests FAILED.";
	} else {
		fill(0,255,0);
		errMsg="All tests passed.";
	}
	text(errMsg,5,20);
}

void output(int ind,String txt,String results,String expected) {
	fill(255,255,255);
	text("["+ind+"] "+txt,xcoord,ycoord+=yinc);
	if (results.equals(expected)) {
		fill(0,255,0);
	} else {
		fill(255,0,0);
		errors=true;
	}
	text(results,xcoord+xoff,ycoord+=yinc);
	ycoord+=yinc;
}

void outputArr(int ind,String txt,String[] results,String[] expected) {
	fill(255,255,255);
	text("["+ind+"] "+txt,xcoord,ycoord+=yinc);

        String resOut="";
        fill(0,255,0);
        for (int i=0;i<results.length;i++) {
           
           if (i>=expected.length || !results[i].equals(expected[i])) {
               fill(255,0,0);
               errors=true;
           }
           resOut=resOut+results[i]+", ";
        }

	text(resOut,xcoord+xoff,ycoord+=yinc);
	ycoord+=yinc;
}
	</script>
	<canvas id="display"></canvas>
	<script type="text/javascript">
	$(document).ready(function(){
	var canvas = document.getElementById('display');
	var script = document.getElementById('script').text;
	var source = script.replace(/[^\.]size\(\)\;/,'size('+ $("body").width() +','+ $("body").height() +');');
	Processing(canvas,source);
	});
	</script><br />
	<b>Test written by <a href="http://zenit.senecac.on.ca/wiki/index.php/User:Mlam19">Matthew Lam</a>
	<pre style="border-style: dotted; border-width: 1px; background-color: #FFFFFF; padding: 2px; margin: 5px">


boolean errors=false;

int xcoord=5;
int xoff=10;
int ycoord=35;
int yinc=15;


void setup() {
  
    PFont font;
		//make sure this font in data dir
    font = loadFont("Eureka-90.vlw"); 
    textFont(font, 12);
    size(500,400);
    background(50);
    noLoop();
} 


void draw() {
        String[] res1=new String[3];
        res1[0]="-01";
        res1[1]="20";
        res1[2]="300";
        int[] inp1=new int[3];
        inp1[0]=-1;
        inp1[1]=20;
        inp1[2]=300;
        outputArr(1,"nf({-1,20,300}, 3)",nf(inp1, 2),res1);
 
        String[] res2=new String[3];
        res2[0]="-001.00";
        res2[1]="020.02";
        res2[2]="300.01";
        float[] inp2=new float[3];
        inp2[0]=-1.002;
        inp2[1]=20.02;
        inp2[2]=300.0123;
        outputArr(2,"nf({-1.002,20.02,300.0123}, 3, 2)",nf(inp2, 3, 2),res2);
        
        String[] res3=new String[3];
        res3[0]="-1";
        res3[1]="20";
        res3[2]="300";
        int[] inp3=new int[3];
        inp3[0]=-1;
        inp3[1]=20;
        inp3[2]=300;
        outputArr(3,"nf({-1,20,300}, -1)",nf(inp3, -1),res3);
        
        String[] res4=new String[3];
        res4[0]="-001";
        res4[1]="000";
        res4[2]="000";
        float[] inp4=new float[3];
        inp4[0]=-1.002;
        inp4[1]=0.49;
        inp4[2]=0.5;
        outputArr(4,"nf({-1.002,0.49,0.5}, 3, -1)",nf(inp4, 3, -1),res4);
        
        String[] res5=new String[3];
        res5[0]="-001";
        res5[1]="001";
        res5[2]="002";
        float[] inp5=new float[3];
        inp5[0]=-1.002;
        inp5[1]=1.49;
        inp5[2]=1.5;
        outputArr(5,"nf({-1.002,1.49,1.5}, 3, -1)",nf(inp5, 3, -1),res5);
 
	xcoord=300;
	ycoord=35;
 
        output(6,"nf(-1, 3)",nf(-1, 3),"-001");
        output(7,"nf(20, 3)",nf(20, 3),"020");
        output(8,"nf(300, 3)",nf(300, 3),"300");
 
	String errMsg="";
	if (errors) {
		fill(255,0,0);
		errMsg="RED tests FAILED.";
	} else {
		fill(0,255,0);
		errMsg="All tests passed.";
	}
	text(errMsg,5,20);
}
 
void output(int ind,String txt,String results,String expected) {
	fill(255,255,255);
	text("["+ind+"] "+txt,xcoord,ycoord+=yinc);
	if (results.equals(expected)) {
		fill(0,255,0);
	} else {
		fill(255,0,0);
		errors=true;
	}
	text(results,xcoord+xoff,ycoord+=yinc);
	ycoord+=yinc;
}
 
void outputArr(int ind,String txt,String[] results,String[] expected) {
	fill(255,255,255);
	text("["+ind+"] "+txt,xcoord,ycoord+=yinc);
 
        String resOut="";
        fill(0,255,0);
        for (int i=0;i<results.length;i++) {
           
           if (i>=expected.length || !results[i].equals(expected[i])) {
               fill(255,0,0);
               errors=true;
           }
           resOut=resOut+results[i]+", ";
        }
 
	text(resOut,xcoord+xoff,ycoord+=yinc);
	ycoord+=yinc;
}

	</pre>

	<br />
</body>
</html>

